package com.sky.wsp.rabbitmq.topic;

import com.sky.wsp.rabbitmq.topic.vo.IDaaSMessage;
import com.sky.wsp.rabbitmq.topic.vo.UserPassword;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @desccription 给三方应用发送MQ消息
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2022/9/29
 */
@Component
public class RabbitMqTopicProducer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired(required = false)
    RabbitTemplate rabbitTemplate;


    /**
     * 发送MQ消息，通知三方应用用户修改密码
     *
     * @param msg
     */
    public void sendUserPassword(IDaaSMessage<UserPassword> msg) {
        if (null == rabbitTemplate) {
            logger.warn("rabbitServer not run");
            return;
        }
        logger.debug("sendUserPassword");
        rabbitTemplate.convertAndSend(TopicMqConfig.USER_PASSWORD_TOPIC_EXCHANGE, msg.getTenantId(), msg);
    }
}
